package com.atguigu.springcloud;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;

/**
 * @author heh
 * @date 2020-04-01
 */
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableHystrix
public class OrderMain8006 {
    public static void main(String[] args) {
        SpringApplication.run(OrderMain8006.class, args);
        // http://localhost:8006/swagger-ui.html
    }
    
    /**
     	* 此配置为了服务监控而配置，与服务容错无关，sprig cloud 升级后的坑
     * ServletRegistrationBean 因为spring boot 默认路径不是“hystrix.stream”
     * 只要在之际的项目配置下面的servlet就可以了
     * @return
     */
    @Bean
    public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
    	HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
    	ServletRegistrationBean<HystrixMetricsStreamServlet> servletRegistrationBean = new ServletRegistrationBean<>(hystrixMetricsStreamServlet);
    	servletRegistrationBean.setLoadOnStartup(1);
    	servletRegistrationBean.addUrlMappings("/hystrix.stream");
    	servletRegistrationBean.setName("HystrixMetricsStreamServlet");
    	return servletRegistrationBean;
    
    }

}
